import tensorflow as tf

# 创建一个形状为[3, 3]的全一矩阵
ones_matrix = tf.ones(shape=[3, 3])
tf.print("Ones Matrix:", ones_matrix)

# 生成从1到12的张量
range_tensor = tf.range(start=1, limit=13, dtype=tf.int32)
tf.print("Range Tensor:", range_tensor)

# 将生成的张量reshape为[3, 4]形状
reshaped_tensor = tf.reshape(range_tensor, shape=[3, 4])
tf.print("Reshaped Tensor:", reshaped_tensor)

# 提取reshaped_tensor中的一部分矩阵
sliced_matrix = reshaped_tensor[0:2, 1:3]
tf.print("Sliced Matrix:", sliced_matrix)

# 计算reshaped_tensor的元素之和
sum_value = tf.reduce_sum(reshaped_tensor)
tf.print("Sum Value:", sum_value)

# 生成形状为[2, 2]的随机正态分布矩阵
random_normal_matrix = tf.random.normal(shape=[2, 2])
tf.print("Random Normal Matrix:", random_normal_matrix)

# 创建一个包含特定整数值的张量
int_tensor = tf.constant([15, 25, 35], dtype=tf.int32)
tf.print("Integer Tensor:", int_tensor)

# 将整数张量转换为浮点数张量
float_tensor = tf.cast(int_tensor, tf.float32)
tf.print("Float Tensor:", float_tensor)

# 创建一个三维常量矩阵
constant_matrix = tf.constant(value=[[[9, 8], [7, 6]], [[5, 4], [3, 2]]])
tf.print("Constant Matrix:", constant_matrix)

# 扩展常量矩阵的维度
expanded_matrix = tf.expand_dims(constant_matrix, axis=3)
tf.print("Expanded Matrix:", expanded_matrix)

# 计算range_tensor的最大值
max_value = tf.reduce_max(range_tensor)
tf.print("Max Value:", max_value)

# 计算range_tensor的最小值
min_value = tf.reduce_min(range_tensor)
tf.print("Min Value:", min_value)

# 创建一个形状为[4, 2]的全零矩阵
zeros_matrix = tf.zeros(shape=[4, 2])
tf.print("Zeros Matrix:", zeros_matrix)

# 计算ones_matrix每一列的元素之和
col_sum = tf.reduce_sum(ones_matrix, axis=0)
tf.print("Column Sum:", col_sum)
